package org.deltaset.meta.internal;

import org.deltaset.meta.Catalog;
import org.deltaset.meta.extension.CatalogProvider;

/**
 *
 * @author dmakariev
 */
public final class DefaultCatalogProvider implements CatalogProvider {

    private final String defaultCatalogResourcePath;
    private final String defaultUnsupportedTemplateSrc;
    private final String metaType;

    public DefaultCatalogProvider(String defaultCatalogResourcePath, String defaultUnsupportedTemplateSrc, String metaType) {
        this.defaultCatalogResourcePath = defaultCatalogResourcePath;
        this.defaultUnsupportedTemplateSrc = defaultUnsupportedTemplateSrc;
        this.metaType=metaType;
    }

    @Override
    public Catalog createCatalog(final String extensionCatalogName) {
        final CatalogBuilder builder = CatalogBuilder.newInstance();
        builder.unsuportedTemplateSrc(defaultUnsupportedTemplateSrc).
                metaType(metaType).
                useResource(defaultCatalogResourcePath);
        if (null != extensionCatalogName) {
            builder.useResource(extensionCatalogName);
        }
        final Catalog catalog = builder.build();
        return catalog;
    }

    @Override
    public Catalog createCatalog() {
        return this.createCatalog(null);
    }
}
